//
//  YYHeadView.m
//  KMedicine
//
//  Created by song on 16/7/6.
//  Copyright © 2016年 caomu. All rights reserved.
//

#import "YYHeadView.h"
#define kHeadImgHight 100

@interface YYHeadView()
@property (nonatomic, weak) UIImageView *head_defult;

@property (nonatomic, weak) UIButton *btn_idCard;
@property (nonatomic, weak) UIButton *btn_0;
@property (nonatomic, weak) UIButton *btn_illness;
@property (nonatomic, weak) UIButton *btn_phone;

@property (nonatomic, weak) UILabel *nameLabel;

@end

@implementation YYHeadView

-(instancetype)init{
    if (self = [super init]) {
        
        [self setupUI];
        
        [self setUserInteractionEnabled:NO];
    }
    
    return self;
}

- (void)setupUI{
    // 初始化
    UIImageView *head_defult = [[UIImageView alloc] init];
    
    UIImage *headImg = [UIImage imageWithContentsOfFile:kFilePath(@"userProtraitPicture.png")];
    
    if (!headImg) {
        headImg = [UIImage imageNamed:@"good_image_default"];
    
    }
    head_defult.image = headImg;
    
    // idCard   小人标志   地点   手机号码   姓名栏
    self.btn_0       = [self buttonWithTitle:@"男 28"       andImgStr:@"0"];
    self.btn_idCard  = [self buttonWithTitle:@"idCard"      andImgStr:@"idCard"];
    self.btn_illness = [self buttonWithTitle:@"上海市"       andImgStr:@"city"];
    self.btn_phone   = [self buttonWithTitle:@"18888888888" andImgStr:@"Newphone"];
    
    UILabel *nameLabel = [[UILabel alloc] init];
    
    NSAttributedString *str = [[NSAttributedString alloc] initWithString:@"张三丰" attributes:@{
                                                              NSForegroundColorAttributeName:[UIColor blueColor],
                                                                         NSFontAttributeName:[UIFont systemFontOfSize:20]
                                                                                            }];
    [nameLabel setAttributedText:str];
    
    [nameLabel sizeToFit];
    [self addSubview:nameLabel];
    
    [self addSubview:head_defult];

    // 赋值
    self.head_defult = head_defult;

    self.nameLabel = nameLabel;
    
    // 空间设置约束
    [self setLayout];
}

- (void)setUI:(UIButton *)subV{
    
    
}


#pragma mark
#pragma mark 设置布局
- (void)setLayout{
    
    [self.head_defult makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.offset(20);
        make.height.width.offset(kHeadImgHight);
    }];
    
    [self.btn_0 makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.head_defult.top);
        make.left.equalTo(self.head_defult.right).offset(10);
        
    }];
    
    [self.btn_idCard makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.btn_0.bottom).offset(5);
        make.left.equalTo(self.head_defult.right).offset(10);
    }];
    
    [self.btn_phone makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.btn_idCard.bottom).offset(5);
        make.left.equalTo(self.head_defult.right).offset(10);
    }];
    
    [self.btn_illness makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.btn_phone.bottom).offset(5);
        make.left.equalTo(self.head_defult.right).offset(10);
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.equalTo(self.head_defult.centerX);
        make.top.equalTo(self.head_defult.bottom).offset(10);
        make.bottom.offset(0);
    }];

}

#pragma mark - 设置 button
- (UIButton *)buttonWithTitle:(NSString *)title andImgStr:(NSString *)imgStr {
    
    UIButton *button = [[UIButton alloc] init];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:imgStr] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    
    button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [self addSubview:button];
    
    [button makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(0);
        make.height.offset(25);
    }];
    
    return button;
}


@end
